package cn.weiwei.WHadoop.hdfs.filesystem;

import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.FileSystem;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.io.IOUtils;

import java.io.InputStream;
import java.net.URI;

/**
 * @author WangWeiwei
 * @version 1.0
 * @sine 17-2-6
 * 直接使用FIleSystem以标准输出格式显示Hadoop文件系统中的文件
 */
public class FileSystemCat {
    public void cat (String uri) throws Exception{
        Configuration conf = new Configuration();
        FileSystem fileSystem = FileSystem.get(URI.create(uri),conf);
        InputStream inputStream = null;
        try {
            inputStream = fileSystem.open(new Path(uri));
            IOUtils.copyBytes(inputStream,System.out,4096,false);
        }finally {
            IOUtils.closeStream(inputStream);
        }
    }
}
